package com.java.tutorials.jdk7.database;

import javax.sql.rowset.JdbcRowSet;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
/**
 * Created by xuzhike on 2016/1/23.
 * http://www.java2s.com/Code/Java/JDK-7/UsingtheRowSetFactoryclass.htm
 */
public class RowSetFactoryTest {
    public static void main(String[] args) throws Exception {
        String databaseUrl = "jdbc:mysql://localhost:3306/pssm?useUnicode=true&amp;characterEncoding=UTF-8";
        String username = "root";
        String password = "";

        RowSetFactory rowSetFactory = null;
        rowSetFactory = RowSetProvider.newFactory(
                "com.sun.rowset.RowSetFactoryImpl", null);
        JdbcRowSet rowSet = rowSetFactory.createJdbcRowSet();

        rowSet.setUrl(databaseUrl);
        rowSet.setUsername(username);
        rowSet.setPassword(password);
        rowSet.setCommand("SELECT * FROM comp_audit_log");
        rowSet.execute();

        while (rowSet.next()) {
            System.out.println(rowSet.getInt("ID") + " - "
                    + rowSet.getString("DB_ACTION"));
        }
    }
}
